
const getStyle = (obj, attr) => {
    if (window.getComputedStyle) {
        //null 如果获取元素伪元素 :before :after
        return window.getComputedStyle(obj, null)[attr];
    }
    return obj.currentStyle[attr];
}


const aniamte = (oEle, attr, target) => {
    clearInterval(oEle.timer);
    oEle.timer = setInterval(() => {
        let current = parseInt(getStyle(oEle, attr));
        let steps = target > current ? 10 : -10;

        //新的位置=当前位置+步长
        oEle.style[attr] = current + steps + "px";

        if (Math.abs(target - current) <= Math.abs(steps)) {
            clearInterval(oEle.timer);
            oEle.style[attr] = target + 'px';
        }
    }, 10)
}

//暴露出去
export default {
    getStyle,
    aniamte
}